package com.ikangtai.shecare.common.baseView.recordButtonView;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;

import com.ikangtai.shecare.R;
import com.ikangtai.shecare.common.RecordFragmentCommonList;
import com.ikangtai.shecare.common.util.PxDxUtil;

/**
 * Created by Administrator on 2016/1/20.
 */
public class RecordSelectOvulationButton extends RecordSelectButton{

    private Context context;
    public static final int RECORD_OVULATION_SELECT_WHITE_BACKGROUND_COLOR = 0;
    public static final int RECORD_OVULATION_SELECT_PURPLE_BACKGROUND_COLOR = 1;
    public static final String RecordSelectOvulationButtonType="OVULATION";

    public RecordSelectOvulationButton(Context context){
        super(context);
        this.context=context;
        setType(RecordSelectOvulationButtonType);
    }
    public RecordSelectOvulationButton(Context context, AttributeSet attrs){
        super(context,attrs);
        this.context=context;
       this.backgroundColor = RECORD_OVULATION_SELECT_WHITE_BACKGROUND_COLOR;
    }

    @Override
    public void setColor(int backGroundColor) {
        super.setColor(backGroundColor);
    }

    @Override
    public void clickAction(View view) {
        RecordSelectOvulationButton recordMensesYesBtn;
        RecordSelectOvulationButton recordMensesNoBtn;
       if(null!=view){
           recordMensesYesBtn=(RecordSelectOvulationButton)view.findViewById(R.id.record_ovulation_btn_yes);
           recordMensesNoBtn=(RecordSelectOvulationButton)view.findViewById(R.id.record_ovulation_btn_no);

        if(backgroundColor == RECORD_OVULATION_SELECT_WHITE_BACKGROUND_COLOR||backgroundColor == RECORD_OVULATION_SELECT_PURPLE_BACKGROUND_COLOR){
            backgroundColor = RECORD_OVULATION_SELECT_PURPLE_BACKGROUND_COLOR;
            if(this.getId()==recordMensesYesBtn.getId()){
                this.setBackground(getResources().getDrawable(R.drawable.record_ovulation_button_pressed));
                this.setTextColor(Color.WHITE);
                recordMensesNoBtn.setColor(RECORD_OVULATION_SELECT_WHITE_BACKGROUND_COLOR);
                recordMensesNoBtn.setBackground(getResources().getDrawable(R.drawable.record_ovulation_button_default));
                recordMensesNoBtn.setTextColor(getResources().getColor(R.color.ovulation_color));}

            if(this.getId()==recordMensesNoBtn.getId()){
                this.setBackground(getResources().getDrawable(R.drawable.record_ovulation_button_pressed));
                this.setTextColor(Color.WHITE);
                recordMensesYesBtn.setColor(RECORD_OVULATION_SELECT_WHITE_BACKGROUND_COLOR);
                recordMensesYesBtn.setBackground(getResources().getDrawable(R.drawable.record_ovulation_button_default));
                recordMensesYesBtn.setTextColor(getResources().getColor(R.color.ovulation_color));
            }

            for(int i=0;i< RecordFragmentCommonList.ovulationTestResultBtn.length;i++){
                if(this.getId() == RecordFragmentCommonList.ovulationTestResultBtn[i]){
                    this.setBackground(getResources().getDrawable(R.drawable.record_ovulation_button_pressed));
                    this.setTextColor(Color.WHITE);
                    this.setPadding(PxDxUtil.dip2px(context, 10),0,0,0);
                    for(int j=0;j< RecordFragmentCommonList.ovulationTestResultBtn.length;j++){
                        if(RecordFragmentCommonList.ovulationTestResultBtn[i] != RecordFragmentCommonList.ovulationTestResultBtn[j]){
                            RecordSelectOvulationButton button = (RecordSelectOvulationButton)view.findViewById(RecordFragmentCommonList.ovulationTestResultBtn[j]);
                            button.setColor(RECORD_OVULATION_SELECT_WHITE_BACKGROUND_COLOR);
                            button.setBackground(getResources().getDrawable(R.drawable.record_ovulation_button_default));
                            button.setTextColor(getResources().getColor(R.color.ovulation_color));
                            button.setPadding(PxDxUtil.dip2px(context,10),0,0,0);
                        }
                    }
                }
            }

        }
       }
    }

}
